#include<iostream>
#include<string>



using namespace std;

class Solution {
public:

    string Multiplybyposition(string& s1, int x, int i)
    {
        string ret;
        while (i--) ret += 0 + '0';
        int t = 0, tail = s1.size() - 1;
        while (tail >= 0 || t)
        {
            if (tail >= 0) t += (s1[tail--] - '0') * x;
            ret += t % 10 + '0';
            t /= 10;
        }

        reverse(ret.begin(), ret.end());
        return ret;
    }
    string Addbyposition(string& s1, string& s2)
    {
        int tails1 = s1.size() - 1, tails2 = s2.size() - 1;
        int t = 0;
        string ret;
        while (tails1 >= 0 || tails2 >= 0 || t)
        {
            if (tails1 >= 0) t += s1[tails1--] - '0';
            if (tails2 >= 0) t += s2[tails2--] - '0';
            ret += t % 10 + '0';
            t /= 10;
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
    string multiply(string num1, string num2) {
        string ss = "0";
        if (num1 == ss || num2 == ss) return ss;
        string ret = "0";
        int n = num2.size() - 1, i = 0;
        while (n >= 0)
        {
            string tmp;
            tmp = Multiplybyposition(num1, num2[n--] - '0', i);
            ret = Addbyposition(ret, tmp);
            i++;
        }

        return ret;
    }
};



int main()
{
    string s1 = "123";
    string s2 = "456";
    Solution A;
    cout << A.multiply(s1, s2) << endl;
    return 0;
}